package kr.hyosang.android.penfo.data;

import java.util.ArrayList;

public class MainPageData {
    public static final int LIST_HOTNOW = 1;
    public static final int LIST_FREEBOARD = 2;
    public static final int LIST_REVIEW = 3;
    public static final int LIST_QNA = 4;
    
    public ArrayList<Article> listHotNow;
    public ArrayList<Article> listFreeboard;
    public ArrayList<Article> listReview;
    public ArrayList<Article> listQnA;
    public ArrayList<Article> allList;
    private int [] nBoardList = {LIST_HOTNOW, LIST_FREEBOARD, LIST_REVIEW, LIST_QNA};
    public String choiceImage;
    public ArrayList<String> featured;
    
    public MainPageData() {
        listHotNow = new ArrayList<Article>();
        listFreeboard = new ArrayList<Article>();
        listReview = new ArrayList<Article>();
        listQnA = new ArrayList<Article>();
        
        allList = new ArrayList<Article>();
        featured = new ArrayList<String>();
    }
    
    public void rearrange() {
        allList.clear();
        
        if(listHotNow.size() > 0) {
	        allList.add(null);
	        allList.addAll(listHotNow);
        }
        
        if(listFreeboard.size() > 0) {
	        allList.add(null);
	        allList.addAll(listFreeboard);
        }
        
        if(listReview.size() > 0) {
	        allList.add(null);
	        allList.addAll(listReview);
        }
        
        if(listQnA.size() > 0) {
	        allList.add(null);
	        allList.addAll(listQnA);
        }
    }
    
    public int getHeaderType(int nIdx) {
    	int [] nInfoArr = {listHotNow.size(), listFreeboard.size(), listReview.size(), listQnA.size()};
    	int nCount = 0;
    	
    	for(int i=0;i<nInfoArr.length;i++) {
    		if(nInfoArr[i] > 0) {
	    		if(nCount == nIdx) {
	    			return nBoardList[i];
	    		}else {
	    			nCount += nInfoArr[i];
	    			nCount += 1;
	    		}
    		}
    	}
    	
    	return -1;
    }
    
    public int getArticleType(int nIdx) {
    	
    	
        int idx = -1;
        
        for(int i=0;i<=nIdx;i++) {
            if(allList.get(i) == null) {
                idx++;
            }
        }
        
        if(idx >= 0) {
            return nBoardList[idx];
        }
        
        return -1;
    }
    
    public Article getArticle(int nIdx) {
        return allList.get(nIdx);
    }
    
    
}